<template>
	<view class="page" :style="{ 'height': h + 'px', 'padding-top': mt + 'px' }">
		<c-nav-bar title="我的订单" :showHome="false"></c-nav-bar>
		<view class="p_top">
			<view class="pt_search">
				<view class="pts_left">
					<image src="https://i.ringzle.com/file/20240129/ad3412950aeb48e48c1cfe86db397eb4.png"></image>
					<input type="text" placeholder="请输入名称/订单号" placeholder-style="ptsl_inp" v-model="keyword" @blur="setKeyword"
						@confirm="confirmKeyword">
				</view>
				<view class="pts_right" @tap="search">搜索</view>
			</view>
			<view class="pt_type">
				<view class="ptt_left" @tap="typeShow = !typeShow">
					<text>{{ typeName }}</text>
					<image class="pttl_img" src="https://i.ringzle.com/file/20240131/7cf113630cea4dcda2df4f5d017969e1.png">
					</image>
				</view>
				<view class="ptt_tabs">
					<view :class="tabIndex == index ? 'active' : ''" v-for="(item, index) in tabList" :key="index"
						@tap="changeTab(item, index)">
						{{ item.name }}
					</view>
				</view>
			</view>
		</view>
		<view class="content" :style="{ 'height': (h - mt - 118) + 'px' }">
			<view class="custom_popup" v-show="typeShow">
				<view class="types">
					<text class="title">类型</text>
					<view class="items">
						<view :class="typeIndex == index ? 'active' : ''" v-for="(item, index) in typeList" :key="index"
							@tap.stop="selectType(item, index)">
							{{ item.name }}
						</view>
					</view>
				</view>
			</view>
			<view class="list">
				<block v-if="typeIndex == 0">
					<ShipOrder ref="rShipOrder" />
				</block>
				<block v-else-if="typeIndex == 1">
					<HotelOrder ref="rHotelOrder" />
				</block>
				<block v-else-if="typeIndex == 2">
					<ScenicOrder ref="rScenicOrder" />
				</block>
				<block v-else-if="typeIndex == 3">
					<ShipHotelOrder ref="rShipHotelOrder" />
				</block>
				<block v-else-if="typeIndex == 4">
					<ShipScenicOrder ref="rShipScenicOrder" />
				</block>
				<block v-else-if="typeIndex == 5">
					<FishJialeOrder ref="rFishJialeOrder" />
				</block>
				<block v-else-if="typeIndex == 6">
					<goodmet ref="goodmet" />
				</block>
			</view>
		</view>
	</view>
</template>

<script>
import AllOrder from './allOrder.vue'; //全部订单
import ShipOrder from './shipOrder.vue'; //船票订单
import HotelOrder from './hotelOrder.vue'; //酒店民宿订单
import ScenicOrder from './scenicOrder.vue'; //景点门票订单
import ShipHotelOrder from './shipHotelOrder.vue'; //船票+住宿订单
import ShipScenicOrder from './shipScenicOrder.vue'; //船票+景点订单
import FishJialeOrder from './fishJialeOrder.vue'; //渔家乐订单
import goodmet from './goodmet.vue'; //餐饮美食订单
export default {
	components: {
		AllOrder,
		ShipOrder,
		HotelOrder,
		ScenicOrder,
		ShipHotelOrder,
		ShipScenicOrder,
		FishJialeOrder,
		goodmet
	},
	data() {
		return {
			h: uni.getSystemInfoSync().windowHeight,
			mt: uni.getSystemInfoSync().statusBarHeight + 44,
			keyword: '',
			type: '', //订单状态：空 全部、 1 待支付、2 待使用、3 待评价、4 退款售后
			typeName: '全部',
			tabList: [{
				type: '',
				name: '全部订单'
			},
			{
				type: 1,
				name: '待支付'
			},
			{
				type: 2,
				name: '待使用'
			},
			{
				type: 3,
				name: '待评价'
			},
			{
				type: 4,
				name: '退款售后'
			}
			],
			tabIndex: 0,
			typeShow: false,
			typeList: [{
				type: 1,
				name: '船票'
			},
			{
				type: 2,
				name: '酒店民宿'
			},
			{
				type: 3,
				name: '景点门票'
			},
			{
				type: 4,
				name: '船票+住宿'
			},
			{
				type: 5,
				name: '船票+景点'
			},
			{
				type: 6,
				name: '渔家乐'
			},
			{
				type: 7,
				name: '餐饮美食'
			}
			],
			typeIndex: 0,
			refsCfg: {
				0: 'rShipOrder',
				1: 'rHotelOrder',
				2: 'rScenicOrder',
				3: 'rShipHotelOrder',
				4: 'rShipScenicOrder',
				5: 'rFishJialeOrder',
				6: 'goodmet'
			}
		}
	},
	onLoad(option) {
		this.type = option.type;
		this.tabIndex = +this.type || 0;
		this.typeName = option.name || '船票';
		if (option.typeIndex) {
			this.typeIndex = +option.typeIndex;
			this.$nextTick(() => {
				this.dealData(2);
			});
		} else {
			this.dealData(2);
		}
	},
	onPullDownRefresh() {
		setTimeout(() => {
			this.dealData(2);
			uni.stopPullDownRefresh();
		}, 1000)
	},
	methods: {
		setKeyword(e) {
			this.keyword = e.target.value;
		},
		confirmKeyword(e) {
			this.keyword = e.target.value;
			this.dealData(1);
		},
		//搜索
		search() {
			this.dealData(1);
		},
		//切换状态
		changeTab(item, index) {
			this.tabIndex = index;
			this.dealData(2);
		},
		//选择订单类型
		selectType(item, index) {
			console.log(item, index);
			this.typeIndex = index;
			this.typeName = item.name;
			this.typeShow = false;
			this.keyword = '';
			this.$nextTick(() => {
				this.dealData(2);
			});
		},
		dealData(type) { //1 搜索、2 获取数据/切换状态
			if (type == 1) this.$refs[this.refsCfg[this.typeIndex]].search(this.keyword);
			else if (type == 2) this.$refs[this.refsCfg[this.typeIndex]].changeStatus(this.tabIndex);
		}
	}
}
</script>

<style scoped lang="less">
::v-deep .orders,
::v-deep scroll-view {
	height: 100% !important;
}

::v-deep .u-modal__content{
	.u-modal__content__text{
		text-align: center;
	}
}

.page {
	background: #F5F8FA;
	padding-bottom: 20rpx;
	box-sizing: border-box;

	.p_top {
		width: 100%;
		padding: 22rpx 20rpx 21rpx;
		box-sizing: border-box;
		background: #FFFFFF;

		.pt_search {
			width: 100%;
			padding: 12rpx;
			box-sizing: border-box;
			border-radius: 38rpx;
			border: 1rpx solid #33C3B8;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.pts_left {
				width: calc(100% - 105rpx);
				padding: 0 18rpx;
				box-sizing: border-box;
				display: flex;
				align-items: center;

				image {
					width: 28rpx;
					height: 28rpx;
				}

				input {
					width: calc(100% - 28rpx);
					padding-left: 20rpx;
					box-sizing: border-box;
					border: none;
					font-size: 24rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #333333;
					line-height: 33rpx;
				}

				.ptsl_inp {
					color: #AAAAAA;
				}
			}

			.pts_right {
				width: 105rpx;
				height: 56rpx;
				background: #33C3B8;
				border-radius: 38rpx;
				line-height: 56rpx;
				text-align: center;
				font-size: 26rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
			}
		}

		.pt_type {
			margin-top: 33rpx;
			width: 100%;
			box-sizing: border-box;
			display: flex;
			align-items: center;

			.ptt_left {
				width: 160rpx;
				height: 60rpx;
				background: #F5F5F5;
				border-radius: 30rpx;
				position: relative;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-right: 20rpx;

				text {
					padding-right: 24rpx;
					font-size: 24rpx;
					font-family: PingFang-SC, PingFang-SC;
					font-weight: bold;
					color: #111111;
					line-height: 33rpx;
				}

				image {
					width: 24rpx;
					height: 24rpx;
					position: absolute;
					top: 50%;
					margin-top: -12rpx;
					right: 16rpx;
				}
			}

			.ptt_tabs {
				width: calc(100% - 180rpx);
				display: flex;
				align-items: center;

				&>view {
					width: 20%;
					text-align: center;
					font-size: 24rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					color: #777777;
					line-height: 36rpx;

					&.active {
						font-weight: bold;
						color: #111111;
					}
				}
			}
		}
	}

	.content {
		width: 100%;
		padding: 0 24rpx;
		box-sizing: border-box;
		position: relative;

		.custom_popup {
			width: 100%;
			height: 100%;
			background: rgba(0, 0, 0, .4);
			top: 0;
			left: 0;
			position: absolute;
			z-index: 999;

			.types {
				width: 100%;
				padding: 30rpx 30rpx 56rpx;
				box-sizing: border-box;
				background: #FFFFFF;

				.title {
					font-size: 30rpx;
					font-family: PingFang-SC, PingFang-SC;
					font-weight: bold;
					color: #111111;
					line-height: 42rpx;
				}

				.items {
					margin-top: 10rpx;
					display: flex;
					flex-wrap: wrap;
					margin-left: -24rpx;

					&>view {
						width: calc(100% / 3 - 24rpx);
						height: 64rpx;
						background: rgba(0, 122, 105, .06);
						border-radius: 16rpx;
						line-height: 64rpx;
						text-align: center;
						margin-top: 20rpx;
						font-size: 26rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						color: #111111;
						margin-left: 24rpx;

						&.active {
							background: #007A69;
							font-weight: bold;
							color: #FFFFFF;
						}
					}
				}
			}
		}

		.list {
			width: 100%;
			height: 100%;
			overflow-y: auto;
		}
	}
}

::v-deep .nodatadiv {
	padding-top: 0;
}
</style>